package leetcode.weekly.week329;

//Solution3Test
public class Solution6 {

	public boolean makeStringsEqual(String s, String target) {
		int zero = 0, one = 0;
		int n = s.length();
		int cntz = 0, cnto = 0;
		boolean zz = false, oo = false, zo = false, oz = false;
		for (int i = 0; i < n; i++) {
			char cs = s.charAt(i);
			char ct = target.charAt(i);
			if (cs == '0') {
				cntz++;
			} else {
				cnto++;
			}
			if (cs == ct) {
				if (cs == '0') {
					zz = true;
				} else {
					oo = true;
				}
				continue;
			}
			if (cs == '0') {
				zo = true;
				zero++;
			} else {
				oz = true;
				one++;
			}
		}
		if (zero == one) {
			return true;
		} else if (one > zero) {
			return (cntz > 0 && zo) || (cnto > 1 && oo);
		} else if (zero > one) {
			return (cnto > 0 && oz) || (cnto > 0 && oo);
		}
		return zero == one;
	}
}
